//
// Created by Suzhen on 2017/2/24.
//

#ifndef ORIONV2_IOBEHAVIOR_H
#define ORIONV2_IOBEHAVIOR_H

#include "Orion.h"
#include "IOBuffer.h"

ORION_V2_NAMESPACE_BEGIN

        /**
         * IOBehavior 中 notify*系列成员函数默认行为，会将数据进行封装，同时提交到Coroutine中
         * 
         */
        class IOBehavior {

        public:
            using OnAcceptCallBack = std::function<void(typename ORION_V2::AbstractAsyncStream *)>;
            using OnOpenCallBack = std::function<void(typename ORION_V2::AbstractAsyncStream *)>;
            using OnClosedCallBack = std::function<void(typename ORION_V2::AbstractAsyncStream *)>;
            using OnDataReadCallBack = std::function<void(typename ORION_V2::AbstractAsyncStream *,
                                                          const RawDataType *data, size_t sz)>;
        public:
            IOBehavior();

            virtual ~IOBehavior();

            void setOnAcceptCallBack(OnAcceptCallBack &&cb);

            void setOnOpenCallBack(OnOpenCallBack &&cb);

            void setOnClosedCallBack(OnClosedCallBack &&cb);

            void setOnDataReadCallBack(OnDataReadCallBack &&cb);

            OnAcceptCallBack getAcceptCallBack() const {
                return onAcceptCb_;
            }

            OnOpenCallBack getOpenCallBack() const {
                return onOpenCb_;
            }

            OnClosedCallBack getClosedCallBack() const {
                return onClosedCb_;
            }

            OnDataReadCallBack getDataReadCallBack() const {
                return onDataReadCb_;
            }

            void notifyOnAccept(typename ORION_V2::AbstractAsyncStream *);

            void notifyOnOpen(typename ORION_V2::AbstractAsyncStream *);

            void notifyOnClosed(typename ORION_V2::AbstractAsyncStream *);

            void notifyOnDataRead(typename ORION_V2::AbstractAsyncStream *,
                                  const RawDataType *,
                                  size_t);

        private:
            OnAcceptCallBack onAcceptCb_;
            OnOpenCallBack onOpenCb_;
            OnClosedCallBack onClosedCb_;
            OnDataReadCallBack onDataReadCb_;

        };

ORION_V2_NAMESPACE_END


#endif //ORIONV2_IOBEHAVIOR_H
